import 'package:flutter/material.dart';

class ListViewDemo1 extends StatefulWidget {
  const ListViewDemo1({Key? key}) : super(key: key);

  @override
  _ListViewDemo1State createState() => _ListViewDemo1State();
}

class _ListViewDemo1State extends State<ListViewDemo1> {
  List<int> _list = [];

  @override
  void initState() {
    super.initState();
    for (var i = 0; i < 100; i++) {
      _list.add(i);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('列表练习'),
      ),
      body: Scrollbar(
        //Scrollbar显示滚动条
        child: RefreshIndicator(
          onRefresh: _onRefresh,
          child: ListView(
            // shrinkWrap: true,
            children: _list.map((e) => Text(e.toString())).toList(),
          ),
        ),
      ),
    );
  }

  Future _onRefresh() async {
    await Future.delayed(Duration(seconds: 3), () {
      print('等待3秒执行');
    });
  }
}
